//
// Created by mio on 25-5-19.
//

#ifndef AACDECODER_H
#define AACDECODER_H
#include <QThread>
#include <atomic>

#include "av_common.h"
#include "AV_Queue.h"

class AVDecoder;
class AudioResampler;
class AACDecoder : public QThread ,public DecodBase
{
    Q_OBJECT
public:
    AACDecoder(AVContext* ac,QObject* parent = nullptr);
    AACDecoder(const AACDecoder&) = delete;
    AACDecoder& operator=(const AACDecoder&) = delete;
    ~AACDecoder();

    int  Open(const AVCodecParameters* codecParamer);

    inline void put_packet(const AVPacketPtr packet){audio_queue_.push(packet);}
    inline bool isFull(){return audio_queue_.size() > 50;}

protected:
    void Close();
    void run() override;

private:
    std::atomic_bool           quit_ = false;
    AVQueue<AVPacketPtr>   audio_queue_;
    AVContext*      avContext_ = nullptr;
    std::unique_ptr<AudioResampler> audioResampler_;
};


#endif //AACDECODER_H
